<!DOCTYPE html>
<html>
<head>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>

    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <!--    <script src="/static/js/framework-ui.js"></script>-->
    <!--    <script src="/static/js/framework-clientdata.js"></script>-->

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/layui.js"></script>
</head>
<body>
<style>
    html, body {
        background-color: #FFF !important;
    }

    .modal-body {
        background-color: #fff;
        padding: 15px
    }

    .page-header {
        margin-top: 15px !important;
    }

    .geographic input {
        width: 100px !important;
        float: left;
        margin-right: 15px;
    }

    .new-content {
        padding: 15px 0px
    }

    .config_img {
        width: 45px;
        height: 45px;
        margin-top: 15px;
    }
    .layui-form-label{
        width:100px!important;
    }
</style>

<div class="modal-body">

    <div class="new-content">
        <form class="form-horizontal layui-form" name="add_form">


            <div class="layui-form-item">
                <label class=" layui-form-label wd-140">*标题:</label>
                <div class="layui-input-block">
                    <input type="text" class="form-control" name="title" placeholder="标题" value="{$detail.title}">
                </div>
            </div>


            <!--<div class="form-group">-->
                <!--<label class="col-sm-1 control-label">缩略图:</label>-->
                <!--<div class="col-sm-4">-->
                    <!--<div class="input-group ">-->
                        <!--<input type="text" id="thumb" name="thumb" value="{$detail.thumb}" class="form-control" autocomplete="off">-->
                        <!--<span class="input-group-btn">-->
                        <!--<button class="btn btn-default" id="upload" type="button" data-original-title="" title="">选择图片</button>-->
                    <!--</span>-->
                    <!--</div>-->
                    <!--<img class="config_img thumb" src="{$detail.thumb}" >-->
                <!--</div>-->
            <!--</div>-->


            <div class="layui-form-item js_photos">
                <label class=" layui-form-label"> *文件</label>
                <div class="layui-input-block logo">
                    <div class="input-group ">
                        <input type="file" name="" class="do_upload" data-val="path"  style="display: none">
                        <input type="text" class="form-control path" name="path" disabled="" value="{$detail.path}" >
                        <input type="hidden" class="form-control path" name="path" value="{$detail.path}" >
                        <span class="group-span-filestyle input-group-btn" tabindex="0">
                            <label class="btn btn-default id_photos" data-original-title="" title="">
                                <span class="glyphicon glyphicon-folder-open"></span>
                                上传
                            </label>
                        </span>
                        </span>
                    </div>
                    {if condition="$detail.path neq ''"}
                    <a target="_blank" href="{$detail.path}">查看文件</a>
                    {/if}
                </div>
            </div>
            <!--图文模型&单页模型-->
            <!--<div class="form-group" >-->
                    <!--<label class="col-sm-1 control-label">*内容:</label>-->
                    <!--<div class="col-sm-8">-->
                        <!--<textarea id="content" >{$detail.content}</textarea>-->
                    <!--</div>-->
            <!--</div>-->


            <div class="layui-form-item">
                <label class=" layui-form-label wd-140">发布日期:</label>
                <div class="layui-input-block">
                    <input type="text" class="form-control time"  name="Wdate" placeholder="发布日期" value="{$detail.Wdate}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class=" layui-form-label wd-140">排序:</label>
                <div class="layui-input-block">
                    <input type="text" class="form-control" name="sort" placeholder="排序" value="{$detail.sort}">
                </div>
            </div>
            <input type="hidden" value="{$detail.status|default=1}" name="status" >
            <input type="hidden" value="{$detail.id}" name="id" >
        </form>
    </div>


<script>

    var newModal = new yii.modal();

    $(".id_photos").click(function () {
        $(this).parent().parent().find(".do_upload").click();
    });

    $('.js_photos').on('change','.do_upload',function(){
        var content = $(this).attr("data-val");
        var formData = new FormData();
        var name = $($(this)).val();
        var files = $($(this))[0].files[0];
        formData.append("file", files);
        formData.append("name", name);
        //另外加的参数
        formData.append("act", "PostImg");
        // var index = layer.msg('正在提交中....');

        $.ajax({
            url: "{:URL('common/upload/ad_upload')}",
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            dataType: 'json',
            success:function (res) {
                $("."+content).val(res.path);
                $("."+content).find("img").attr("src",res.path);
            }
            ,error:function (res) {
                alert('错误');
            }
        });
    })

    $("#upload").click(function () {
        $(newModal.getid()).show();
        newModal.initialization({
            url: "{:URL('common/upload/index')}",
            type: "post",
            data:{
                type:'detail'
            }
        });
    });

    newModal.on("upload",function(data){
        var images = '';
        $(newModal.getid()).find("#data-area .newimages .active img").each(function () {
            images = $(this).attr('src');
            return false
        })
        $(newModal.getid()).hide();
        //$(".modal-backdrop").remove();
        //$('#nowMainProjectDataForm').modal('hide');
        $(newModal.getid()).find(".modal").hide();
        $("#thumb").val(images);
        $(".config_img").attr("src",images)
    });
    layui.extend({
        tinymce: '/static/tinymce/tinymce'
    });
    layui.use(['form', 'jquery', 'layer', 'laydate','tinymce'], function () { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var tinymce = layui.tinymce;
        //同时绑定多个
        lay('.time').each(function(){
            laydate.render({
                elem: this
                ,trigger: 'click'
                ,type: 'date'
                ,theme: 'molv'
            });
        });


        tinymce.render({
            elem:'#content',
            height: 600,
            images_upload_handler: function (blobInfo, succFun, failFun) {
                var xhr, formData;
                var file = blobInfo.blob();//转化为易于理解的file对象
                xhr = new XMLHttpRequest();
                xhr.withCredentials = false;
                xhr.open('POST', "{:URL('/common/upload/textUpload')}");
                xhr.onload = function() {
                    var json;
                    json = JSON.parse(xhr.responseText);
                    succFun(json.path);
                };
                formData = new FormData();
                formData.append('file', file, file.name );//此处与源文档不一样
                xhr.send(formData);
            }
        },(opt, edit) => {

        });
        $("#newsave").click(function () {
            // var content = tinymce.get('#content').getContent();
            var data = $("form").serializeArray();
            // data.push({name: "content", value: content});
            var community_id =  $('select[name="community_id"]').val();
            $.ajax({
                type: 'post',
                url: "{:URL('admin/affiche/doAffiche')}",
                data: data,
                dataType: 'JSON',
                success: function (res) {
                    if (res.code != 0) {
                        layer.alert(res.msg);
                    } else {
                        if(community_id==0){
                            community_id = -1;
                        }
                        window.location.href = "{:URL('admin/affiche/index')}?community_id="+community_id;
                    }
                },
                error: function (res) {

                }
            });
        })


        form.render('select');

    });

</script>

</body>
</html>